home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / VIDEO.C < prev    next >
Text File  |  1991-10-02  |  4KB  |  155 lines

  1. /* --------------------- video.c -------------------- */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <dos.h>
  5. #include <string.h>
  6. #include <conio.h>
  7. #include "dflat.h"
  8.  
  9. static unsigned video_address;
  10. /* -- read a rectangle of video memory into a save buffer -- */
  11. void getvideo(RECT rc, void far *bf)
  12. {
  13.     int ht = RectBottom(rc)-RectTop(rc)+1;
  14.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  15.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  16.     hide_mousecursor();
  17.     while (ht--)    {
  18.         movedata(video_address, vadr, FP_SEG(bf),
  19.                 FP_OFF(bf), bytes_row);
  20.         vadr += SCREENWIDTH*2;
  21.         bf = (char far *)bf + bytes_row;
  22.     }
  23.     show_mousecursor();
  24. }
  25.  
  26. /* -- write a rectangle of video memory from a save buffer -- */
  27. void storevideo(RECT rc, void far *bf)
  28. {
  29.     int ht = RectBottom(rc)-RectTop(rc)+1;
  30.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  31.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  32.     hide_mousecursor();
  33.     while (ht--)    {
  34.         movedata(FP_SEG(bf), FP_OFF(bf), video_address,
  35.                 vadr, bytes_row);
  36.         vadr += SCREENWIDTH*2;
  37.         bf = (char far *)bf + bytes_row;
  38.     }
  39.     show_mousecursor();
  40. }
  41.  
  42. /* -------- read a character of video memory ------- */
  43. int GetVideoChar(int x, int y)
  44. {
  45.     int c;
  46.     hide_mousecursor();
  47.     c = peek(video_address, vad(x,y));
  48.     show_mousecursor();
  49.     return c;
  50. }
  51.  
  52. /* -------- write a character of video memory ------- */
  53. void PutVideoChar(int x, int y, int c)
  54. {
  55.     if (x < SCREENWIDTH && y < SCREENHEIGHT)    {
  56.         hide_mousecursor();
  57.         poke(video_address, vad(x,y), c);
  58.         show_mousecursor();
  59.     }
  60. }
  61.  
  62. /* -------- write a character to a window ------- */
  63. void wputch(WINDOW wnd, int c, int x, int y)
  64. {
  65.     int x1 = GetLeft(wnd)+x;
  66.     int y1 = GetTop(wnd)+y;
  67.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  68.         hide_mousecursor();
  69.         poke(video_address,
  70.             vad(x1,y1),(c & 255) |
  71.                 (clr(foreground, background) << 8));
  72.         show_mousecursor();
  73.     }
  74. }
  75.  
  76. /* ------- write a string to a window ---------- */
  77. void wputs(WINDOW wnd, void *s, int x, int y)
  78. {
  79.     int x1 = GetLeft(wnd)+x;
  80.     int y1 = GetTop(wnd)+y;
  81.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  82.         int fg = foreground;
  83.         int bg = background;
  84.         unsigned char *str, *ss;
  85.         int *ln, *cp1;
  86.         int len;
  87.  
  88.         if ((ss = malloc(400)) != NULL)    {
  89.             if ((ln = malloc(400)) != NULL)    {
  90.                 cp1 = ln;
  91.                 strncpy(ss, s, 399);
  92.                 clipline(wnd, x, ss);
  93.                 hide_mousecursor();
  94.                 str = ss;
  95.                 while (*str)    {
  96.                     if (*str == CHANGECOLOR)    {
  97.                         str++;
  98.                         foreground = (*str++) & 0x7f;
  99.                         background = (*str++) & 0x7f;
  100.                         continue;
  101.                     }
  102.                     if (*str == RESETCOLOR)    {
  103.                         foreground = fg & 0x7f;
  104.                         background = bg & 0x7f;
  105.                         str++;
  106.                         continue;
  107.                     }
  108.                     *cp1++ = (*str & 255) |
  109.                         (clr(foreground, background) << 8);
  110.                     str++;
  111.                 }
  112.                 foreground = fg;
  113.                 background = bg;
  114.                 len = (int)(cp1-ln);
  115.                 if (x1+len > SCREENWIDTH)
  116.                     len = SCREENWIDTH-x1;
  117.                 movedata(FP_SEG(ln), FP_OFF(ln), video_address, vad(x1,y1), len*2);
  118.                 show_mousecursor();
  119.                 free(ln);
  120.             }
  121.             free(ss);
  122.         }
  123.     }
  124. }
  125.  
  126. /* --------- get the current video mode -------- */
  127. void get_videomode(void)
  128. {
  129.     videomode();
  130.     /* ---- Monochrome Display Adaptor or text mode ---- */
  131.     if (ismono())
  132.         video_address = 0xb000;
  133.     else
  134.         /* ------ Text mode -------- */
  135.         video_address = 0xb800 + video_page;
  136. }
  137.  
  138. /* --------- scroll the window. d: 1 = up, 0 = dn ---------- */
  139. void scroll_window(WINDOW wnd, RECT rc, int d)
  140. {
  141.     union REGS regs;
  142.     hide_mousecursor();
  143.     regs.h.cl = RectLeft(rc);
  144.     regs.h.ch = RectTop(rc);
  145.     regs.h.dl = RectRight(rc);
  146.     regs.h.dh = RectBottom(rc);
  147.     regs.h.bh = clr(WndForeground(wnd),WndBackground(wnd));
  148.     regs.h.ah = 7 - d;
  149.     regs.h.al = 1;
  150.     int86(VIDEO, ®s, ®s);
  151.     show_mousecursor();
  152. }
  153.  
  154.  
  155.